package com.shiliuzi.www.util.mqUtil;

import com.shiliuzi.www.util.CommonUtil;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import sun.rmi.transport.ObjectTable;

import javax.annotation.Resource;

import static com.shiliuzi.www.config.RabbitMQConfig.EMAIL_EXCHANGE;
import static com.shiliuzi.www.config.RabbitMQConfig.RABBIT_EXCHANGE;

@Component
public class MQWrite {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @Resource
    private CommonUtil commonUtil;

    /**
     * 发送普通消息
     * @param target
     */
    public void sendMessage(Object target) {
        rabbitTemplate.convertAndSend(RABBIT_EXCHANGE,"rabbit.returns",commonUtil.jsonWriter(target));
    }

    /**
     * 发送延迟消息
     * @param target
     */
    public void sendDeadMessage(Object target) {
        rabbitTemplate.convertAndSend(RABBIT_EXCHANGE,"ttl.returns",commonUtil.jsonWriter(target));
    }

    /**
     * 发送邮件，确保成功
     * @param target
     */
    public void sendEmailMessage(Object target) {
        rabbitTemplate.convertAndSend(EMAIL_EXCHANGE,"email.send",commonUtil.jsonWriter(target));
    }
}
